package avatarFrame;

import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import person.PersonRecorder;

import constants.Constants;

public class AvatarInfoPanel extends JPanel {
	private JLabel nameLabel, sexLabel, ageLabel, heightLabel, weightLabel, heartLabel, caloriIntakeLabel, caloriCosumeLabel, caloriTotalLabel, armLabel, legLabel, absLabel, dateLabel;
	private ArrayList<JLabel> heartLabelArray, armMuscleArray, legMuscleArray, absMuscleArray;
	private PersonRecorder personRecorder;

	private int caloriConsumed = 0;
	private int caloriIntaken = 0;

	public AvatarInfoPanel() {
		this.setLayout(null);
		this.setSize(Constants.AVATAR_PANEL_WIDTH, Constants.AVATAR_PANEL_HEIGHT);
		this.setBackground(Constants.PANEL_BACKGROUND_COLOR);

		// name label
		nameLabel = new JLabel("Name : ");
		nameLabel.setBounds(0, 50, 100, 20);
		this.add(nameLabel);

		// sex label
		sexLabel = new JLabel("Sex : ");
		sexLabel.setBounds(0, 75, 100, 20);
		this.add(sexLabel);

		// age label
		ageLabel = new JLabel("Age : ");
		ageLabel.setBounds(0, 100, 100, 20);
		this.add(ageLabel);

		// height label
		heightLabel = new JLabel("Height : ");
		heightLabel.setBounds(0, 125, 100, 20);
		this.add(heightLabel);

		// weight label
		weightLabel = new JLabel("Weight : ");
		weightLabel.setBounds(0, 150, 100, 20);
		this.add(weightLabel);

		// heartRate label
		heartLabel = new JLabel();
		heartLabel.setText("Heart Rating : ");
		heartLabel.setBounds(0, 200, 100, 20);
		this.add(heartLabel);

		heartLabelArray = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
			JLabel tempLabel = new JLabel();
			tempLabel.setBounds(80 + i * 30, 200, 30, 30);
			tempLabel.setIcon(null);
			this.add(tempLabel);
			heartLabelArray.add(tempLabel);
		}

		// arm muscle label
		armLabel = new JLabel();
		armLabel.setText("Arm Muscle : ");
		armLabel.setBounds(0, 250, 100, 20);
		this.add(armLabel);

		armMuscleArray = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
			JLabel tempLabel = new JLabel();
			tempLabel.setBounds(80 + i * 30, 250, 30, 30);
			tempLabel.setIcon(null);
			this.add(tempLabel);
			armMuscleArray.add(tempLabel);
		}

		// leg muscle label
		legLabel = new JLabel();
		legLabel.setText("Leg Muscle : ");
		legLabel.setBounds(0, 300, 100, 20);
		this.add(legLabel);

		legMuscleArray = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
			JLabel tempLabel = new JLabel();
			tempLabel.setBounds(80 + i * 30, 300, 30, 30);
			tempLabel.setIcon(null);
			this.add(tempLabel);
			legMuscleArray.add(tempLabel);
		}

		// abs muscle label
		absLabel = new JLabel();
		absLabel.setText("ABS Muscle : ");
		absLabel.setBounds(0, 350, 100, 20);
		this.add(absLabel);

		absMuscleArray = new ArrayList<>();
		for (int i = 0; i < 7; i++) {
			JLabel tempLabel = new JLabel();
			tempLabel.setBounds(80 + i * 30, 350, 30, 30);
			tempLabel.setIcon(null);
			this.add(tempLabel);
			absMuscleArray.add(tempLabel);
		}

		// calori label
		caloriIntakeLabel = new JLabel("Intaken Calori : Input your intaken Calori");
		caloriIntakeLabel.setBounds(0, 400, 276, 20);
		this.add(caloriIntakeLabel);

		caloriCosumeLabel = new JLabel("Consumed Calori : Do Exercise");
		caloriCosumeLabel.setBounds(0, 420, 276, 20);
		this.add(caloriCosumeLabel);

		caloriTotalLabel = new JLabel("Total Calori : ");
		caloriTotalLabel.setBounds(0, 440, 276, 20);
		this.add(caloriTotalLabel);

		// date label
		dateLabel = new JLabel("Date : ");
		dateLabel.setBounds(0, 491, 100, 20);
		this.add(dateLabel);
	}

	public void setPersonRecorder(PersonRecorder personRecorder) {
		this.personRecorder = personRecorder;
		this.nameLabel.setText("Name : " + personRecorder.getPerson().getName());
		this.sexLabel.setText("Sex : " + personRecorder.getPerson().getSex().toString());
		this.ageLabel.setText("Age : " + personRecorder.getPerson().getAge());
		this.heightLabel.setText("Height : " + personRecorder.getPersonInfoArray().get(0).getHeight() + " cm");
		this.weightLabel.setText("Weight : " + personRecorder.getPersonInfoArray().get(0).getWeight() + " kg");
	}

	public void setHeartRate(int starImgCount) {
		// set star image
		for (int i = 0; i < 7; i++) {
			heartLabelArray.get(i).setIcon(null);
		}
		for (int i = 0; i <= starImgCount; i++) {
			heartLabelArray.get(i).setIcon(new ImageIcon(Constants.STAR_FULL_IMG));
		}

		repaint();
	}

	public void setArmMuscleRate(int starImgCount) {
		for (int i = 0; i < 7; i++) {
			armMuscleArray.get(i).setIcon(null);
		}
		for (int i = 0; i <= starImgCount; i++) {
			armMuscleArray.get(i).setIcon(new ImageIcon(Constants.STAR_FULL_IMG));
		}

		repaint();
	}

	public void setLegMuscleRate(int starImgCount) {
		for (int i = 0; i < 7; i++) {
			legMuscleArray.get(i).setIcon(null);
		}
		for (int i = 0; i <= starImgCount; i++) {
			legMuscleArray.get(i).setIcon(new ImageIcon(Constants.STAR_FULL_IMG));
		}

		repaint();
	}

	public void setABSMuscleRate(int starImgCount) {
		for (int i = 0; i < 7; i++) {
			absMuscleArray.get(i).setIcon(null);
		}
		for (int i = 0; i <= starImgCount; i++) {
			absMuscleArray.get(i).setIcon(new ImageIcon(Constants.STAR_FULL_IMG));
		}

		repaint();
	}

	public void addConsumedCalori(int consumedCalori) {
		this.caloriConsumed += consumedCalori;

		caloriCosumeLabel.setText("Consumed Calori : " + caloriConsumed + "kcal");
		caloriTotalLabel.setText("Total Calori : " + (caloriIntaken - caloriConsumed) + "kcal");
	}

	public void addIntakenCalori(int caloriIntake) {
		this.caloriIntaken += caloriIntake;

		caloriIntakeLabel.setText("Intaken Calori : " + caloriIntake + "kcal");
		caloriTotalLabel.setText("Total Calori : " + (caloriIntaken - caloriConsumed) + "kcal");
	}

	public void clear() {
		for (int i = 0; i < 7; i++) {
			heartLabelArray.get(i).setIcon(null);
		}
		for (int i = 0; i < 7; i++) {
			armMuscleArray.get(i).setIcon(null);
		}
		for (int i = 0; i < 7; i++) {
			legMuscleArray.get(i).setIcon(null);
		}
		for (int i = 0; i < 7; i++) {
			absMuscleArray.get(i).setIcon(null);
		}
	}

}
